home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
ldb.zip
/
SDATA.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-18
|
2KB
|
122 lines
/*
sdata.cpp
10-18-91
Streamable Data: Loose Data Binder v1.4
Copyright 1991
John W. Small
All rights reserved
PSW / Power SoftWare
P.O. Box 10072
McLean, Virginia 22102 8072 USA
John Small
Voice: (703) 759-3838
CIS: 73757,2233
*/
#include "sdata.hpp"
#include <string.h>
void SData::construct(voiD D, unsigned sizeofData,
unsigned Did, int dup)
{
this->Did = Did;
if ((this->dup = dup) != 0)
if (sizeofData && D)
if ((this->D = new char
[sizeofData]) != voiD0)
memcpy(this->D,D,
this->sizeofData
=sizeofData);
else {
this->sizeofData = 0;
this->dup = 0;
}
else {
this->sizeofData = 0;
this->dup = 0;
this->D = voiD0;
}
else if ((this->D = D) == voiD0)
this->sizeofData = 0;
else
this->sizeofData = sizeofData;
}
ostream& SData::store(ostream& os)
{
os << sizeofData << endm << Did << endm;
if (!os)
serror("unable to store SData"
": sizeofData and Did");
else if (sizeofData) {
os.write((const char *)D,sizeofData);
if (!os)
serror("unable to store"
" SData data");
}
return os;
}
StreamablE SData::load(istream& is,
StreamablE InstancE)
{
unsigned sizeofData, Did;
voiD D = voiD0;
if (!(is >> sizeofData >> nextm >> Did
>> nextm)) {
lserror("unable to load SData"
": sizeofData and Did",
ID_CLASS);
return StreamablE0;
}
if (sizeofData) {
if ((D = new char[sizeofData])
!= voiD0) {
is.read((char *)D,sizeofData);
if (!is) {
lserror("loading "
"SData data",
ID_CLASS);
delete D;
return StreamablE0;
}
}
else {
lserror("unable to allocate "
"memory for SData data",
ID_CLASS);
is.ignore(sizeofData);
return StreamablE0;
}
}
if (!InstancE)
if ((InstancE = (StreamablE)
new SData
(UNIQUE_STREAMABLE))
== StreamablE0) {
lserror("unable to construct"
" SData",ID_CLASS);
delete D;
return StreamablE0;
}
((SDatA)InstancE)->
construct(D,sizeofData,Did,0);
((SDatA)InstancE)->dup = 1;
return InstancE;
}
SData::SData(char * s, int dup)
: Streamable(UNIQUE_STREAMABLE,ID_CLASS)
{
construct(s,(dup?(s?(strlen(s)+1):0):0),
DID_String,dup);
}